package com.formula.propertyshop.view.common;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.formula.propertyshop.R;

public class BSDCalculatorFragment extends Fragment{
	private Button btnCalculate;
	private EditText txtPrice;
	private TextView txtResult;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.bsd_calculator, container, false);
    btnCalculate = (Button) rootView.findViewById(R.id.btnBSD);
    txtPrice = (EditText) rootView.findViewById(R.id.txtPrice);
    txtResult = (TextView) rootView.findViewById(R.id.txtResult);
    btnCalculate.setOnClickListener(new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			if(validateData()){
				double price = Double.parseDouble(txtPrice.getText().toString());
				double value = ((double)3/100)*price - 5400;
				txtResult.setText("BSD: "+value);
			}
		}
	});
//    // Demonstration of a collection-browsing activity.
//    rootView.findViewById(R.id.demo_collection_button)
//            .setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    Intent intent = new Intent(getActivity(), CollectionDemoActivity.class);
//                    startActivity(intent);
//                }
//            });
//
//    // Demonstration of navigating to external activities.
//    rootView.findViewById(R.id.demo_external_activity)
//            .setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View view) {
//                    // Create an intent that asks the user to pick a photo, but using
//                    // FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET, ensures that relaunching
//                    // the application from the device home screen does not return
//                    // to the external activity.
//                    Intent externalActivityIntent = new Intent(Intent.ACTION_PICK);
//                    externalActivityIntent.setType("image/*");
//                    externalActivityIntent.addFlags(
//                            Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
//                    startActivity(externalActivityIntent);
//                }
//            });

    return rootView;
	}
	private boolean validateData(){
		Animation animFadein = AnimationUtils.loadAnimation(this.getActivity(),R.anim.sequence_button);
		if(txtPrice.getText().toString().isEmpty()){
			Toast.makeText(this.getActivity(), R.string.msg_field_not_empty, Toast.LENGTH_SHORT).show();
			txtPrice.startAnimation(animFadein);
			return false;
		}
		return true;
	}
}
